package com.zqs.compareface.server.apiserver;

import com.aliyun.facebody20191230.models.CompareFaceRequest;
import com.aliyun.facebody20191230.models.CompareFaceResponse;
import com.aliyun.teaopenapi.models.Config;
import com.zqs.compareface.myenum.*;

/**
 * @program: FaceCompar
 * @description:
 * @author: ZQS
 * @create: 2021-08-08 02:13
 */
public class AliyunApiJudge {
    private static final Float JUDGE = 61F;


    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new com.aliyun.facebody20191230.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.facebody20191230.Client client = AliyunApiJudge.createClient("AI5******jycW", "**g8rH*****Pi*PS");
        CompareFaceRequest compareFaceRequest = new CompareFaceRequest()
                .setQualityScoreThreshold(60F)
                .setImageURLA("https://www.abc.com/uril=16283133KiZ%2FwjT0lxctGfPw%3D")
                .setImageURLB("https://www.abc.com/Expires=162831eyId=TMP.3KtHMqw8%3D");
        // 复制代码运行请自行打印 API 的返回值
        CompareFaceResponse y= client.compareFace(compareFaceRequest);
/*        byte yo = y.body.data.confidence.byteValue();
        double yo2 = y.body.data.confidence.doubleValue();
        byte yo3 = y.body.getData().confidence.byteValue();
        Set set = y.body.toMap().entrySet();
        System.out.println(set.size());
        for (Object s:set
             ) {
            System.out.println(s);
        }

        Map map = y.body.toMap();
        System.out.println(map.size());
        for (Object m:map.entrySet()
             ) {
            System.out.println(m);

        }*/
        Float result = y.body.getData().confidence;
        System.out.println(result);
        System.out.println("=============================");
        System.out.println(getJUDGE(result));
    }

    public static String getJUDGE(Float result) {
        if (result>JUDGE){
            return Judges.IS.getJudges();
        }else {
            return Judges.ISNOT.getJudges();
        }
    }

}